package com.tongshu.naive.chat.infrastructure.common;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class EasyResult {
    private Integer code; // 1 失败；0 成功
    private String msg; // 错误信息
    private Long count; // 数据列表长度
    private Object data; // 返回数据

    public EasyResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static EasyResult buildEasyResultError(String message) {
        return new EasyResult(1, message);
    }

    public static EasyResult buildEasyResultError(Exception e) {
        return new EasyResult(1, e.getMessage());
    }

    public static EasyResult buildEasyResultSuccess(Object data) {
        return new EasyResult(0, "", 1L, data);
    }

    public static EasyResult buildEasyResultSuccess(Long count, Object data) {
        return new EasyResult(0, "", count, data);
    }

    public static EasyResult buildEasyResultSuccess() {
        return new EasyResult(0, "");
    }
}
